import 'package:get/get.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/vo/activity_subsidies_vo.dart';
import 'package:xinxuan/vo/common_vo/common_pagination_vo.dart';

class SubsidyPageController extends GetxController {

  var activitySubsidiesVo = ActivitySubsidiesVo(
    data: [],
    meta: ActivitySubsidiesMeta(
      totalSubsidy: '0.00',
      pagination: CommonPagination(
        total: 0,
        currentPage: 1
      )
    )
  ).obs;

  @override
  void onReady() {
    getActivitySubsidies();
    super.onReady();
  }

  /// 获取补贴金发放列表
  getActivitySubsidies() async {
    activitySubsidiesVo.value.meta!.pagination!.currentPage = 1;
    ActivitySubsidiesVo tempVo = await HttpUtilService.getActivitySubsidies(page: activitySubsidiesVo.value.meta!.pagination!.currentPage!);
    activitySubsidiesVo.value = tempVo;
    update();
  }

  /// 获取更多补贴金发放列表
  onLoadActivitySubsidies() async {
    if (activitySubsidiesVo.value.meta!.pagination!.total! <= activitySubsidiesVo.value.data!.length) {
      return;
    }
    activitySubsidiesVo.value.meta!.pagination!.currentPage = activitySubsidiesVo.value.meta!.pagination!.currentPage! + 1;
    ActivitySubsidiesVo tempVo = await HttpUtilService.getActivitySubsidies(page: activitySubsidiesVo.value.meta!.pagination!.currentPage!);
    activitySubsidiesVo.value.data!.addAll(tempVo.data!);
    update();
  }
}